//
//  YKNewFeatureController.m
//  youkan
//
//  Created by mac mini on 16/2/27.
//  Copyright © 2016年 Honsintech. All rights reserved.
//

#import "YKNewFeatureController.h"
/** 新特性界面的cell */
#import "YKNewFatureCell.h"
@interface YKNewFeatureController ()
/** 分页控制器 */
@property(nonatomic,strong)UIPageControl *control;
@end

@implementation YKNewFeatureController

static NSString * const reuseIdentifier = @"Cell";
//     初始化写特性界面控制器
-(instancetype)init{
//    初始化collectionView的约束/布局
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
//    获取屏幕的宽高，比使用控制器的view的frame更准确
    layout.itemSize =[UIScreen mainScreen].bounds.size;
    layout.minimumLineSpacing=0;
//    设置滚动的方向
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    return [super initWithCollectionViewLayout:layout];
}
- (void)viewDidLoad {
    [super viewDidLoad];
//    self.view.backgroundColor =[UIColor redColor];
//   collectionView 背景颜色
    self.collectionView.backgroundColor = [UIColor greenColor];
//    collectionView 中cell的样式
    [self.collectionView registerClass:[YKNewFatureCell class] forCellWithReuseIdentifier:reuseIdentifier];
//    分页功能
    self.collectionView.pagingEnabled = YES;
//    弹性效果
    self.collectionView.bounces = NO;
//    隐藏横向滚动条
    self.collectionView.showsHorizontalScrollIndicator = NO;
    [self setUpPageControll];
}
//设置分页
-(void)setUpPageControll{
    UIPageControl *controll = [[UIPageControl alloc]init];
    controll.numberOfPages = 4 ;
    controll.pageIndicatorTintColor = [UIColor whiteColor];
    controll.currentPageIndicatorTintColor =[UIColor purpleColor];
    controll.center = CGPointMake(self.view.width*0.5, self.view.height-20);
    _control = controll;
    [self.view addSubview:controll];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark UIScrollView代理-滑动方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int page = scrollView.contentOffset.x /scrollView.bounds.size.width+0.5;
    _control.currentPage = page;
}
#pragma mark- UICollectionViewDataSource-分组
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
//每组中的条目
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}
//每个cell的内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    YKNewFatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
    NSString *imageName = [NSString stringWithFormat:@"new_feature_%ld",indexPath.row+1];
    if (screenH<480) {
            imageName = [NSString stringWithFormat:@"new_feature_%ld-568h",indexPath.row + 1];
    }
    cell.image = [UIImage imageNamed:imageName];
    [cell setIndexPath:indexPath count:4];
//    YKLog(@"%@",cell);
    return cell;
}

#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
}
*/

@end
